#-*-coding: utf-8-*-

# Version: 0.1
# Author: Don Li <iedon@126.com>
# License: Copyright(c) 2017 Don.Li
# Summary:

import sys, os
from os.path import abspath, dirname, join, pardir, pathsep

def run_with_source():
    _argv = sys.argv
    return ((len(_argv) > 0) and (_argv[0].rfind('.py') >= 0))


_ROOTPATH_CACHED = None
def root_path():
    global _ROOTPATH_CACHED

    if not _ROOTPATH_CACHED:
        _curr_path = dirname(__file__)

        if run_with_source():
            _relpath = ''.join((_curr_path, '/', pardir, '/', pardir))
        else:
            _relpath = ''.join((_curr_path.rsplit('/', 1)[0], '/', pardir))

        _ROOTPATH_CACHED = abspath(_relpath) + '/'

        #print(_curr_path, _relpath, _ROOTPATH_CACHED)

    return _ROOTPATH_CACHED

def default_config_path():
    return root_path() + 'etc/spiker.conf'

